define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'manystore/shop/index' + location.search,
                    add_url: 'manystore/shop/add',
                    edit_url: 'manystore/shop/edit',
                    del_url: 'manystore/shop/del',
                    multi_url: 'manystore/shop/multi',
                    import_url: 'manystore/shop/import',
                    table: 'manystore_shop',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'logo', title: __('Logo'), operate: 'LIKE'},
                        {field: 'address_city', title: __('Address_city'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'tel', title: __('Tel'), operate: 'LIKE'},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'banji',
                                    text: __('班级列表'),
                                    title: __('班级列表'),
                                    classname: 'btn btn-xs btn-success btn-primary btn-dialog btn-area-big',
                                    extend: 'data-area=\'["95%", "95%"]\'',
                                    icon: 'fa',
                                    url: function(row){
                                        let _url = Config.moduleurl + '/manystore/banji/index?shop_id='+row.id;
                                        return _url;
                                    },
                                    visible: function (row) {
                                        return true;
                                    }
                                },
                                {
                                    name: 'banji',
                                    text: __('监控平台'),
                                    title: __('监控平台'),
                                    classname: 'btn btn-xs btn-success btn-primary btn-dialog btn-area-big',
                                    extend: 'data-area=\'["95%", "95%"]\'',
                                    icon: 'fa',
                                    url: function(row){
                                        let _url = Config.moduleurl + '/manystore/monitor?shop_id='+row.id;
                                        // let _url = Config.moduleurl + '/myadmin/camera?company_id='+row.id;
                                        return _url;
                                    },
                                    visible: function (row) {
                                        return true;
                                    }
                                }
                            ]
                        }
                        ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
